using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.ObjCRuntime;

namespace ComBrowser
{


	public class WebMainViewDelegate: UIWebViewDelegate
	{
 
		public MainViewController ctrl;
		
		public WebMainViewDelegate (MainViewController Controller)
		{
			this.ctrl = Controller;
		}
		
		public override bool ShouldStartLoad (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
		{
			if (request.Url.AbsoluteString.Contains ("#command"))
			{
				//Console.WriteLine (request.Url.Fragment);
				if (request.Url.Fragment.Contains ("command"))
				{
					this.ctrl.ToggleMenu ();
					webView.EvaluateJavascript ("document.location='#';");//make the view refresh so clicking the same will run again the click
				
				}
				return false;
				
			}
			//Console.WriteLine ("ShouldStart");
			return true;
		}
 
		public override void LoadingFinished (UIWebView webView)
		{
			//base.LoadingFinished (webView);
		}
 
		
		
		
	}
}
